package com.tanhua.app.controller;

import com.tanhua.app.service.MessageService;
import com.tanhua.model.pojo.UserInfo;
import com.tanhua.model.vo.PageResult;
import com.tanhua.model.vo.UserInfoVo;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping("/messages")
public class MessageController {

    @Autowired
    private MessageService messageService;

    /**
     * 根据用户环信id查询用户详情信息
     * @param huanxinId
     * @return
     */
    @GetMapping("/userinfo")
    public ResponseEntity findUserInfo(String huanxinId){
        //1.调用Service层执行业务逻辑
        UserInfoVo userInfoVo = messageService.findUserInfoByhuanxinId(huanxinId);

        //2.返回结果
        return ResponseEntity.ok(userInfoVo);
    }


    //    POST /messages/contacts
    @PostMapping("/contacts")
    public ResponseEntity contacts(@RequestBody Map param) {
        //1.获取参数，调用Service层执行业务逻辑
        Long friendId = Long.valueOf(param.get("userId").toString());
        messageService.contacts(friendId);

        //2.返回结果
        return ResponseEntity.ok(null);
    }

//    GET /messages/contacts
    @GetMapping("/contacts")
    public ResponseEntity contacts(Integer page, Integer pagesize , String keyword){
        //1.通过Service执行业务逻辑
        PageResult pageResult = messageService.findFriends(page,pagesize,keyword);

        //2.返货结果
        return ResponseEntity.ok(pageResult);
    }
}
